fix: track opencode session switches - #2455
Conversation
📝 WalkthroughWalkthroughOpenCode now tracks the TUI-selected root session through a dedicated plugin. Installation manages the plugin and JSONC configuration. Terminal state distinguishes local selection from server activity and rejects unrelated session reports. ChangesOpenCode TUI session selection
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant OpenCodeTUI
participant HerdrTUIPlugin
participant TerminalState
OpenCodeTUI->>HerdrTUIPlugin: Select root session
HerdrTUIPlugin->>TerminalState: Report unsequenced "select"
TerminalState->>TerminalState: Reconcile local session ownership
OpenCodeTUI->>TerminalState: Send server session activity
TerminalState-->>OpenCodeTUI: Reject mismatched session report
Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 9dc12150-e42a-4e5c-b532-02d4ecce4fe4
📒 Files selected for processing (5)
docs/next/CHANGELOG.mdsrc/integration/assets/opencode/herdr-agent-state.jssrc/integration/assets/opencode/herdr-agent-state.test.tssrc/integration/mod.rssrc/terminal/state.rs
Greptile SummaryThe PR adds pane-local OpenCode session-selection reporting and updates durable session reconciliation so native restore follows the conversation selected in the TUI while rejecting server-global cross-talk.
Confidence Score: 5/5The PR appears safe to merge because no blocking failure remains within the eligible follow-up-review scope. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| src/integration/assets/opencode/herdr-tui-session.js | Adds pane-local polling of the selected root OpenCode session and reports selection events with bounded retries and lifecycle cleanup. |
| src/terminal/state.rs | Adds OpenCode selection reconciliation, deferred startup anchoring, and cross-talk rejection while preserving existing lifecycle authority. |
| src/integration/opencode_config.rs | Adds JSONC-preserving management of the OpenCode TUI plugin registration. |
| src/integration/targets.rs | Extends OpenCode installation and removal to manage the TUI plugin and its configuration entry. |
| src/integration/registry.rs | Requires both the versioned TUI asset and its configuration entry for the OpenCode integration to be current. |
| src/integration/assets/opencode/herdr-agent-state.js | Stops promoting server-global session creation into an authoritative local session switch. |
Sequence Diagram
sequenceDiagram
participant TUI as OpenCode TUI
participant Plugin as herdr-tui-session.js
participant API as Herdr pane API
participant State as TerminalState
participant Store as Durable session identity
TUI->>Plugin: Select root conversation
Plugin->>Plugin: Poll route and reject child sessions
Plugin->>API: "report_agent_session(source=select)"
API->>State: Set selected session reference
alt OpenCode process detected
State->>Store: Reanchor durable identity
else Process not detected yet
State->>State: Suppress and retain replacement
State->>Store: Apply replacement after detection
end
Note over State: Server-global activity for another root is ignored
Reviews (4): Last reviewed commit: "fix: track opencode tui session selectio..." | Re-trigger Greptile
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: c7ae0178-b40a-47ec-ba71-8dd4d1caf285
📒 Files selected for processing (2)
src/integration/assets/opencode/herdr-agent-state.jssrc/integration/assets/opencode/herdr-agent-state.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/integration/assets/opencode/herdr-agent-state.js
bbcbfc7 to
c62f51c
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (3)
src/integration/assets/opencode/herdr-tui-session.test.ts (1)
112-125: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider covering the exhausted-retry branch.
SELECTION_RETRY_DELAYS_MShas three entries. After the last retry,herdr-tui-session.jssetsnextReportAttoNumber.POSITIVE_INFINITYand stops reporting the same selection. No test asserts that the reporting stops. A test that waits past the final delay and asserts a stable request count would lock in that boundary.src/terminal/state.rs (2)
1374-1375: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider recording the stale session when a selection clears suppression.
selection_can_reconcileremoves the suppression entry for the source without inspectingsuppressed.reason. Every other removal site distinguishesHookClearfromProcessExit.clear_full_lifecycle_hook_suppression_for_detected_agentrecords the suppressedsession_refas a stale session before it drops aHookClearentry (lines 1098-1106). This path drops it silently, so a later report that carries the previous session ref is not filtered byfull_lifecycle_hook_report_matches_stale_session.The
opencode_cross_talkguard at lines 863-870 rejects that report while the process is present and the anchor differs, so the reachable exposure is small. Recording the stale session here would keep the two paths consistent.♻️ Suggested change
if selection_can_reconcile { - self.suppressed_full_lifecycle_hook_reports.remove(&source); + if let Some(suppressed) = self.suppressed_full_lifecycle_hook_reports.remove(&source) { + if let Some(suppressed_ref) = suppressed + .session_ref + .filter(|suppressed_ref| suppressed_ref != &session_ref) + { + self.remember_stale_full_lifecycle_hook_session( + source.clone(), + suppressed.agent_label, + suppressed_ref, + ); + } + } } else if full_lifecycle_source && unsequenced_selection {
4620-4656: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider adding a boundary test for cross-talk while the process is absent.
opencode_cross_talkat lines 863-870 requiresprocess_present. When the process is absent, a report carrying a different session ref still reaches the buffering path at lines 906-953. That asymmetry is intentional, but no test pins it. A test that clears the detected agent and then sends a mismatched sequenced report would document the boundary.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: aec6c888-df3f-48b4-b55f-1b0f88080b93
📒 Files selected for processing (16)
docs/next/CHANGELOG.mdjustfilesrc/agent_resume.rssrc/cli/integration.rssrc/integration/actions.rssrc/integration/assets/opencode/herdr-agent-state.jssrc/integration/assets/opencode/herdr-agent-state.test.tssrc/integration/assets/opencode/herdr-tui-session.jssrc/integration/assets/opencode/herdr-tui-session.test.tssrc/integration/mod.rssrc/integration/opencode_config.rssrc/integration/registry.rssrc/integration/targets.rssrc/integration/tests.rssrc/integration/types.rssrc/terminal/state.rs
🚧 Files skipped from review as they are similar to previous changes (2)
- docs/next/CHANGELOG.md
- src/integration/assets/opencode/herdr-agent-state.js
Summary
tui.jsoncentry without blocking OpenCode's config migrationValidation
just checkrefs #2450